package ort.views.controllers;

import java.util.Timer;

import javax.swing.BorderFactory;

import ort.constants.Constants;
import ort.utils.RemindTask;
import ort.views.UI;

public class FormActionController {

	private static UI form = UI.getFrame();

	public static void startNewRound() {
		
		form.resetTimer();
		
		if (!GameController.getInstance().isFightEnd()) {
			
			form.timer = new Timer();
			form.timer.schedule(new RemindTask(), 0, Constants.SECONDS_TIME_UNIT);
			
			changeRoundButtonsEnable(true);
			GameController.getInstance().startRound();
			changeRoundLabel();
		}
		
	
	}
	
	public static void knokout(int boxerId){
		GameController.getInstance().knockOut(boxerId);
	}
	
	public static void throwTowel(int boxerId){
		GameController.getInstance().throwTowel(boxerId);
	}
	
	public static void changeEndFightLabels(){
		form.btnNewRound.setEnabled(false);
		form.btnNewRound.setText("Pelea terminada");
		form.lblRound.setText("Pelea terminada");
		form.message.setVisible(true);
	}
	
	public static void changeRoundButtonsEnable(boolean enable){
		
		form.btnBox1Count.setEnabled(enable);
		form.btnBox2Count.setEnabled(enable);
		form.btnBox1Kick.setEnabled(enable);
		form.btnBox2Kick.setEnabled(enable);
		form.btnWinBox1KO.setEnabled(enable);
		form.btnWinBox2KO.setEnabled(enable);
		form.btnWinBox1TT.setEnabled(enable);
		form.btnWinBox2TT.setEnabled(enable);
		form.btnNewRound.setEnabled(!enable);
	}
	
	public static void changeRoundLabel(){
		form.lblRound.setText("Round " + GameController.getInstance().getActualRound() );
		form.lblPelea.setText("Pelea " + GameController.getInstance().getFight().getFightType().getLable());
		form.lblRound.setBorder(BorderFactory.createRaisedBevelBorder());
		form.lblPelea.setBorder(BorderFactory.createRaisedBevelBorder());
		form.label_4.setBorder(BorderFactory.createRaisedBevelBorder());
		form.label_4.setText("" + GameController.getInstance().getFight().getTotalRounds());
		form.label_5.setText("-");
	}
	
	
	public static void resetRoundPoints(){
		
		form.lblPositivePointsBoxer1.setText("0");
		form.lblPositivePointsBoxer2.setText("0");
		form.lblNegativePointsBoxer1.setText("0");
		form.lblNegativePointsBoxer2.setText("0");
	}
	
	public static void addScoreBoxer(int boxerId) {
		int points = 0;
		if (boxerId == 1) {
			points = new Double(GameController.getInstance().getActualRoundScore().addScoreToBoxer1()).intValue();
			form.lblPositivePointsBoxer1.setText(String.valueOf(points));
		}else if (boxerId == 2){
			points = new Double(GameController.getInstance().getActualRoundScore().addScoreToBoxer2()).intValue();
			form.lblPositivePointsBoxer2.setText(String.valueOf(points));
		}
	}
	
	public static void addCountBoxer(int boxerId) {
		int points = 0;
		if (boxerId == 1) {
			points = new Double(GameController.getInstance().getActualRoundScore().addCountToBoxer1()).intValue();
			form.lblNegativePointsBoxer1.setText(String.valueOf(points));
		}else if (boxerId == 2){
			points = new Double(GameController.getInstance().getActualRoundScore().addCountToBoxer2()).intValue();
			form.lblNegativePointsBoxer2.setText(String.valueOf(points));
		}
	}

}
